package hot_100;

import java.util.Arrays;

public class 分割等和子集 {
    public static void main(String[] args) {
        int[] nums = {1, 2, 5};
        boolean i = canPartition(nums);
        System.out.println(i);
    }

    public static boolean canPartition(int[] nums) {
        int maxx = Arrays.stream(nums).sum();
        if (maxx % 2 == 1)
            return false;
        int n = nums.length;
        int[] dp = new int[20010];
        dp[0] = 1;
        for (int i = 0; i < n; i++) {
            for (int j = maxx >> 1; j >= nums[i]; j--) {
                int v = j - nums[i];
                if (dp[v] == 1)
                    dp[j] = 1;
            }
        }
        return dp[maxx >> 1] == 1;
    }
}
